package com.wencai.test;

import com.wencai.bean.IndexStocks;
import com.wencai.util.CombineUtils;
import com.wencai.util.IOUtils;

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.StringJoiner;

/**
 * @author wangpan
 * @date 2023/5/10
 */
public class Combine {
    private static String dir = "D:\\Users\\Administrator\\Desktop\\记录\\概念\\";

    private static String outerDir = "D:\\Users\\Administrator\\Desktop\\记录\\";

    public static void main(String[] args) throws IOException {
        File f = new File(dir);
        String[] list = f.list();
        StringBuilder builder = new StringBuilder();
        for (String child : list) {
            if (child.matches("\\d+\\.txt")) {
                String date = child.replaceAll("(\\d+)\\D+", "$1");
                List<String> dataList = IOUtils.readFromFile(dir + child);
                List<IndexStocks> indexStocks = CombineUtils.convertData(dataList, date);
                for (IndexStocks idx : indexStocks) {
                    if (idx.getFirstStockName() == null || idx.getFirstStockName().isEmpty()) {
                        builder.append("*************************").append("\n");
                        continue;
                    }
                    builder.append(date);
                    StringJoiner joiner = new StringJoiner(" ");
                    joiner.add(idx.getFirstStockName()).add(wrap(idx.getSecondStockName())).add(wrap(idx.getThirdStockName()));
                    builder.append(" ").append(joiner).append("\n");
                }
            }
        }
        IOUtils.writeFile(outerDir + "all.txt", builder.toString());
    }

    private static String wrap(String in) {
        return in == null ? "" : in;
    }
}
